﻿using MQ.Core.Common;
using MQ.Core.Db;
using MQ.Core.IService.System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace MQ.Core.Service.System
{
    public abstract class BaseService : IBaseService
    {
        private IBaseRepository baseRepository;
        public BaseService(IBaseRepository baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public void Add<T>(T entity) where T : class
        {
            baseRepository.Add(entity);
        }

        public Task AddAsync<T>(T entity) where T : class
        {
            return baseRepository.AddAsync(entity);
        }

        public void Delete<T>(T entity) where T:class
        {
            baseRepository.Delete(entity);
        }

        public abstract void Delete(string ids);

        public Task DeleteAsync<T>(T entity) where T : class
        {
            return baseRepository.DeleteAsync(entity);
        }

        public abstract Task DeleteAsync(string ids);

        public T GetEntity<T>(long id) where T : class
        {
            return baseRepository.GetEntity<T>(id);
        }

        public Task<T> GetEntityAsync<T>(long id) where T : class
        {
            return baseRepository.GetEntityAsync<T>(id);
        }

        public abstract IEnumerable<T> GetList<T>(string query) where T : class;

        public abstract Task<IEnumerable<T>> GetListAsync<T>(string query) where T : class;

        public abstract IEnumerable<T> GetPageList<T>(Pagination pagination, string query) where T : class;

        public abstract Task<IEnumerable<T>> GetPageListAsync<T>(Pagination pagination, string query) where T : class;

        public void Update<T>(T entity) where T : class
        {
            baseRepository.Update(entity);
        }

        public Task UpdateAsync<T>(T entity) where T : class
        {
            return baseRepository.UpdateAsync(entity);
        }
    }
}
